<template>
    <div  class="pagination-container">
        <el-pagination
            v-model:current-page="currentPage"
            v-model:page-size="pageSize"
            :background="background"
            :layout="layout"
            :page-sizes="pageSizes"
            :pager-count="pagerCount"
            :total="total"
            @sizeChange="handleSizeChange"
            @currentChange="handleCurrentChange"
           
        />
        <!--  :hide-on-single-page="true" -->
    </div>
</template>

<script setup>
import { computed } from 'vue';

const props = defineProps({
    total: {
        required: true,
        type: Number,
    },
    page: {
        type: Number,
        default: 1,
    },
    limit: {
        type: Number,
        default: 10,
    },
    pageSizes: {
        type: Array,
        default() {
            return [10,20, 50, 100, 200, 1000,];
        },
    },
    pagerCount: {
        type: Number,
        default:  7,
    },
    layout: {
        type: String,
        default: 'total, sizes, prev, pager, next, jumper',
    },
    background: {
        type: Boolean,
        default: true,
    },
    autoScroll: {
        type: Boolean,
        default: true,
    },
});

const emit = defineEmits(['update:page', 'update:limit', 'pagination']);
const currentPage = computed({
    get() {
        return props.page;
    },
    set(val) {
        emit('update:page', val);
    },
});
const pageSize = computed({
    get() {
        return props.limit;
    },
    set(val) {
        emit('update:limit', val);
    },
});
function handleSizeChange(val) {
    if (currentPage * val > props.total) {
        currentPage = 1;
    }
    emit('pagination', { page: currentPage, limit: val });
}
function handleCurrentChange(val) {
    emit('pagination', { page: val, limit: pageSize });
}
</script>

<style scoped>
  .pagination-container {
    background: white;
    /* position: fixed; */
    margin-top: 20px;
    right: 20px;
    bottom: 3vh;
    z-index: 99999;
  }

  .pagination-container.hidden {
    display: none;
  }
  .el-pagination {
    float: right;
    padding: 7px 16px 0px 16px;
  }
</style>
